@extends('layout.adminlayout')
@section('css')
 <script src="/admin/js/metisMenu.min.js"></script>
 <script src="/admin/js/custom.js"></script>
 <link href="/admin/css/area_info.css" rel="stylesheet">
 <link href="/admin/css/custom.css" rel="stylesheet">
 <link href="/admin/css/add_manage.css" rel="stylesheet">
 <link href="/admin/css/select_building.css" rel="stylesheet">
@endsection
@section('content')
     <div class="forms"> 
      <div class=" form-grids row form-grids-right"> 
       <div class="widget-shadow " data-example-id="basic-forms"> 
        <div class="form-title"> 
         <h4>房间编辑:</h4> 
        </div> 
        <div class="form-body"> 
        <form method="post" class="form-horizontal" style="position:relative">
         {{csrf_field()}}
          <div class="form-group"> 
           <label for="inputEmail3" class="col-sm-2 control-label" style="width: 33%;float: left; margin-top: 11px"> 所属区域 : </label> 
           <li class="area_info"> 
            <div class="col-sm-6"> 
             <select name="area" id="area" class="form-control1" ;="" style="float: right;width: 64%;">
              <option value="0">请选择区域</option>
              @if($area != null)
               @foreach($area as $v)
                <option value="{{$v['a_id']}}"
                        @if($v['a_id'] == $data['a_id'])
                        selected
                        @endif
                >{{$v['a_name']}}</option>
               @endforeach
              @endif
             </select>
            </div>
           </li>
          </div>
         <div class="form-group"> 
           <label for="inputEmail3" class="col-sm-2 control-label" style="width:33%;float: left;    top: 11px;"> 建&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp筑 : </label> 
           <li class="area_info"> 
            <div class="col-sm-3"> 
             <select name="building" id="building" class="form-control1" style="width: 64%;float: right;">
                 <option value="0">请选择建筑</option>
                 @if($building != null)
                     @foreach($building as $v)
                         <option value="{{$v['b_id']}}"
                                 @if($v['b_id'] == $data['b_id'])
                                 selected
                                 @endif
                         >{{$v['b_name']}}</option>
                     @endforeach
                 @endif
             </select>
            </div> </li> 
          </div>
           <div class="form-group"> 
           <label for="inputPassword3" class="col-sm-2 control-label" style="width: 33%;float: left;    margin-top: 6px">房间名称 : </label> 
           <div class="col-sm-6">
            <input type="hidden" id="r_id" value="{{$data['r_id']}}">
            <input type="text" class="form-control" name="room" id="room" placeholder="房间名称" style="float: right;width: 64%;" value="{{$data['r_name']}}"/>
           </div> 
          </div> 
           <div class="form-group"> 
           <label for="inputPassword3" class="col-sm-2 control-label" style="width: 33%;float: left;    margin-top: 7px">所在楼层 : </label> 
           <div class="col-sm-6"> 
            <input type="text" class="form-control" name="floor" id="floor" placeholder="所在楼层" style="float: right;width: 64%;" value="{{$data['r_floor']}}"/>
           </div> 
          </div>
          <div class="form-group"> 
           <label for="inputPassword3" class="col-sm-2 control-label" style="width: 33%;float: left;    margin-top: 8px"> 负&nbsp&nbsp责&nbsp&nbsp人 : </label> 
           <div class="col-sm-6"> 
            <input type="text" class="form-control" name="manage" placeholder="负责人" id="manage" style="width: 31%;float: left;margin-left: 0.93em;" /> 
            <button type="button" class="btn btn-default" id="add" style="float: right;width: 5em;padding: 0.5em;">添加</button> 
           </div> 
          </div> 
          <div class="form-group"> 
           <label for="inputPassword3" class="col-sm-2 control-label"> </label> 
           <div class="col-sm-6" id="latitude"> 
            <ul id="ul" style="border:0px; width:100%; padding:0px; background:none; height:100%;">
             @foreach($data['mma_username'] as $v)
              <li><div class="a">&nbsp;<span class="mng">{{$v}}</span>&nbsp;<img src="/admin/images/error1.png" alt="" class="img">&nbsp;</div></li>
             @endforeach
            </ul> 
           </div> 
          </div> 
         
          <div class="col-sm-offset-2"> 
           <button type="button" class="btn btn-default" id="sub" style="width: 90%;">提交</button>
          </div> 
         </form> 
        </div> 
       </div> 
      </div> 
     </div> 
     <script>
     //区域建筑联动
	$('#area').change(function () {
		var areaId = $('#area').val();
		var dd = '<option class="dstyle" value="">请选择</option>';
		$.ajax({
			type:'post',
			url:'/admin/room/getbuild',
            async:false,
            data:{
                "_token": $("input[name=_token]").val(),
                'areaId':areaId,
            },
            dataType:'json',
            success:function (data) {
                for(var i=0;i<data.length;i++){
                    dd += '<option class="dstyle" value="'+data[i]['b_id']+'">'+data[i]['b_name']+'</option>';
				}
                $('#building').empty();
                $('#building').append(dd);
            }
		})
    })
     //提交表单
     $('#sub').click(function () {
         var area = $('#area').val();
         var building = $('#building').val();
         var room = $('#room').val();
         var floor = $('#floor').val();
         var r_id = $('#r_id').val();
         var manage = new Array();
         $('.mng').each(function () {
             manage.push($(this).html());
         });
         if(area != 0 && building != 0 && room != '' && floor != ''){
             $.ajax({
                 type:'post',
                 url:'/admin/room/edit',
                 async:false,
                 data:{
                     "_token": $("input[name=_token]").val(),
                     'r_id':r_id,
                     'area':area,
                     'building':building,
                     'room':room,
                     'floor':floor,
                     'manage':manage
                 },
                 dataType:'json',
                 success:function (data) {
                     location.href = '/admin/room/index';
                 }
             })
         }else{
             alert('信息填写不完整或经纬度填写不合法')
             return false;
         }
     });
</script>
@endsection
@section('lastjs')
 <script src="/admin/js/add_manage.js"></script>
 {{--<script src="/admin/js/select_building.js"></script>--}}
@endsection
